<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增物联网卡充值记录')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-renew-add">
            <input name="deviceId" th:value="${deviceId}" class="form-control" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">充值卡号：</label>
                <div class="col-sm-8">
                    <input name="rechargeNo" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">充值人：</label>
                <div class="col-sm-8">
                    <input name="rechargeUser" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">有效期限(年)：</label>
                <div class="col-sm-8">
                    <input id="effectiveDuration" name="effectiveDuration" onkeyup="calcExpire()" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">到期时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input id="expireTime" name="expireTime" class="form-control" placeholder="yyyy-mm-dd HH:mm:ss" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "biz/renew"
        $("#form-renew-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-renew-add').serialize());
            }
        }

        /**
         * 计算过期时间
         */
        function calcExpire(){
            var effectiveDuration = $("#effectiveDuration").val();
            $.get(prefix + "/calcExpire?effectiveDuration="+effectiveDuration,function (result){
                console.log(result);
                $("#expireTime").val(result.data);
            })
        }

        $("input[name='expireTime']").datetimepicker({
            format: "yyyy-mm-dd HH:mm:ss",
            minView: "1",
            autoclose: true
            // format: "yyyy-mm-dd",
            // minView: "month",
            // autoclose: true
        });
    </script>
</body>
</html>